package com.bandit.controller.front;

import com.bandit.pojo.Role;
import com.bandit.pojo.Teacher;
import com.bandit.service.RoleService;
import com.bandit.service.TeacherService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.List;

@Controller
@RequestMapping("/front")
@Slf4j
public class TeachersFrontController {

    private static final String prefix = "front";

    @Autowired
    TeacherService teacherService;

    @Autowired
    RoleService roleService;


    @RequestMapping("/teachers/list")
    public String teachersList(Model model){
        List<Teacher> teachers = teacherService.selectTeacherList(new Teacher());
        List<Role> roleList = roleService.getRoleList(new Role());
        model.addAttribute("teacherList",teachers);
        model.addAttribute("roleList",roleList);
        return prefix+"/teachers";
    }

    @RequestMapping("/teachers/toDetails/{tid}")
    public String teacherDetails(@PathVariable("tid") int tid,Model model){
        Teacher teacher = teacherService.selectTeacherByTid(tid);
        List<Role> roleList = roleService.getRoleList(new Role());
        model.addAttribute("teacher",teacher);
        model.addAttribute("roleList",roleList);
        return prefix + "/teacherDetails";
    }


}
